package com.bolingcavalry.crm.aftersales.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.entity.aftersales.AfterSales;
import com.vo.AfterSales.AfterSalesVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.repository.query.Param;

import java.util.List;

@Mapper
public interface AfterSalesMapper  extends BaseMapper<AfterSales> {

    //根据id查询改售后总括表的订单编号，根据订单编号去通知单 任务单 确认单 总结单 中查询是否存在这个订单编号的数据

    int checkserviceOrders(String serviceNumber);

    int checkTaskOrders(String serviceNumber);

    int checkConfirmationOrders(String serviceNumber);

    int checkSummaryOrders(String serviceNumber);

    IPage<AfterSalesVO> getConfirmationOrdersByPage(Page<AfterSalesVO> page,
                                                    @Param("customerName") String customerName,
                                                    @Param("serviceNumber") String serviceNumber,
                                                    @Param("receiverName") String receiverName,
                                                    @Param("startTime") String startTime,
                                                    @Param("endTime") String endTime,
                                                    @Param("status") String status);

    @Select("SELECT id FROM after_sales WHERE order_number LIKE CONCAT('%', #{orderNumber}, '%')")
    List<Long> selectIdsByOrderNumber(String orderNumber);

    //本月售后问题
    Long countMonthly();

    //全年售后问题
    Long countAnnual();

    //进行中的售后问题
    Long countInProgress();

    //本月已完成的售后问题
    Long countCompletedThisMonth();
    //获取联系人id根据售后单号
    List<Long> getReceiverName(String orderNumber);

    List<Long> selectCustomerCompanyIdsByName(String customerName);

    @Select("SELECT * FROM after_sales WHERE order_number = #{orderNumber}")
    AfterSales selectByOrderNumber(String orderNumber);

    void updateStatusByOrderNumber(@Param("orderNumber") String orderNumber, @Param("status") String status);


    List<Long> selectIdsByOrderNumberYearPrefix(@Param("yearPrefix") String yearPrefix);

    List<Long> selectIdsByOrderNumberYearMonthPrefix(@Param("yearMonthPrefix") String yearMonthPrefix);

    String getMaxOrderNumberByPrefix(@Param("prefix") String prefix);


    boolean checkReceiver(String username);

    @Select("SELECT id FROM after_sales WHERE order_number = #{ordernumber}")
    Long getAfterSalesIdByNumber(Long ordernumber);
}